Skip to content

Conversation

@machichima
Copy link
Member

@machichima machichima commented Jul 13, 2025

Tracking issue

Closes flyteorg/flyte#6474

Why are the changes needed?

When running task locally, using optional list values types (i.e. dict[str, list[str] | None] | None) will cause error. However, when running such task on the cluster it works

What changes were proposed in this pull request?

Error occurs when we call _are_types_castable(List[Sample], Union). In original code, the check for collection type will directly return False, which indicates that List[Sample] is not castable to Union[List[Sample], None], leading to the error.

In this PR, I deal with union_type first in _are_types_castable function to overcome this problem.

How was this patch tested?

Test with the following script. See result in Screenshots section.

from flytekit import task

@task
def complex_task(data: dict[str, list[str] | None] | None) -> dict[str, list[str] | None] | None:
    return data

def test_complex_task() -> dict[str, list[str] | None] | None:
    return complex_task(data={"key": ["value1", "value2"]})


if __name__ == "__main__":
    print(test_complex_task())

Setup process

Screenshots

Successfully execute the above script:

image

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

This pull request fixes a bug in type casting for optional dictionary values, ensuring the `_are_types_castable` function properly handles union types. It also includes minor code cleanup to enhance error handling in type transformations.

@codecov
Copy link

codecov bot commented Jul 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.59%. Comparing base (4c889d6) to head (fe63bdf).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3294      +/-   ##
==========================================
+ Coverage   76.42%   76.59%   +0.16%     
==========================================
  Files         215      215              
  Lines       22545    22548       +3     
  Branches     2969     2969              
==========================================
+ Hits        17230    17270      +40     
+ Misses       4498     4474      -24     
+ Partials      817      804      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kumare3
Copy link
Contributor

kumare3 commented Jul 14, 2025

I tested it looks good, thank you

Copy link
Member

@pingsutw pingsutw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @machichima

@pingsutw pingsutw merged commit 001e3ab into flyteorg:master Jul 16, 2025
228 of 230 checks passed
Atharva1723 pushed a commit to Atharva1723/flytekit that referenced this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Local testing using optional dicts with optional values does not work

3 participants